#ifndef _LEXER_H_
#define _LEXER_H_

#include <string>

using namespace std;

#include "error.h"

class Lexer {
public:
    const char EOFF = 0;
protected:
    string input;   // 输入字符串
    int p = 0;      // 当前字符的索引
    char c;         // 当前字符
public:
    Lexer(string input) {
        this->input = input;
        c = input[p];
    }

    void consume() {
        p++;
        if (p >= input.size())
            c = EOFF;
        else
            c = input[p];
    }

    void match(char x) {
        if (c == x)
            consume();
        else {
            string s = "expecting ";
            s.push_back(x);
            s += "; found ";
            s.push_back(c);
            throw Error(s);
        }
    }
};

#endif
